import util from '@/static/js/util.js';

const state = {
	moduleName:'muu_minishop',
	config: {
		style: 'Blue'
	},
}

const getters = {

}

const mutations = {
	UPDATE_CONFIG(state, config) {
		state.config = config
	},
}

const actions = {
	/**
	 * 全局配置
	 */
	getConfig({commit,state}) {
		return new Promise((resolve, reject) => {
			const config = util.muuCache(`${state.moduleName}_config`)
			if(config){
				state.config = config;
				resolve(config)
			}else{
				let url = '';
					//#ifdef MP-WEIXIN
					url = 'entry/wxapp/config'
					//#endif
					//#ifdef H5
					url = 'entry/site/config'
					//#endif
				util.request({
					url: url,
					data: {
						action : '',
						m: state.moduleName
					},
					success: (res) => {
						if (res.data.code == 200) {
							util.muuCache(`${state.moduleName}_config`, res.data.data)
							commit('UPDATE_CONFIG',res.data.data);
						}
						resolve(res.data.data)
					}
				})
			}
		})
	}
	
}

export default {
	namespaced: true,
	state,
	getters,
	mutations,
	actions
}
